<!doctype html>
<html class="no-js fixed-layout">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>首页</title>
  <meta name="description" content="index">
  <meta name="keywords" content="index">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <link rel="icon" type="image/png" href="/static/assets/i/favicon.png">
  <link rel="apple-touch-icon-precomposed" href="/static/assets/i/app-icon72x72@2x.png">
  <meta name="apple-mobile-web-app-title" content="Amaze UI" />
  <link rel="stylesheet" href="/static/assets/css/amazeui.min.css"/>
  <link rel="stylesheet" href="/static/assets/css/admin.css">
  <style type="text/css">
    .input_width{
      width: 90%;
    }
  </style>
</head>
<body>



  <div class="admin-content">
    <div class="admin-content-body">

      <div class="am-g">


 
        <div class="am-u-sm-12 am-u-md-12 ">
          <!--中间侧块 注意下面是form表-->
          
          <div class="am-form-group">

            <div class="am-g am-margin-top am-form-group">
              <div class="am-u-md-2 am-text-right">账号：</div>
              <div class="am-u-md-3 am-u-end" style="padding-left: 0px;">
                <input type="text"  class="am-input-xl  input_width" placeholder="仅支持英文和数字" maxlength="50" onblur="if(/[^0-9a-zA-Z]/g.test(value))AlertMSG('仅支持英文和数字')" id='login_name' name='login_name' required="">
              </div>
              <div class="am-u-md-2 am-text-right">角色：</div>
              <div class="am-u-md-3 am-u-end" style="padding-left: 0px;">

                <select  id='role' name='role' class="input_width" required="">
                  {% for i in jsalist %}

                  <option value={{ i.role_id }} >{{ i.name }}</option>

                  {% endfor %}  
                </select>
                      
              </div>
            </div>
            <hr/>
            <div class="am-g am-margin-top am-form-group">
              <div class="am-u-md-2 am-text-right">姓名：</div>
              <div class="am-u-md-3 am-u-end" style="padding-left: 0px;">
                <input type="text"  class="am-input-xl input_width" id='real_name' name='real_name' required=""  maxlength="50" >
              </div>
              <div class="am-u-md-2 am-text-right">性别：</div>
              <div class="am-u-md-3 am-u-end" style="padding-left: 0px;">
                <select  id='sex' name='sex' class="input_width" required="">
                      <option value="2">未知</option>
                      <option value="1">男</option>
                      <option value="0">女</option>
                      
                </select>
              </div>
            </div>
            <hr/>
            <div class="am-g am-margin-top am-form-group">
              <div class="am-u-md-2 am-text-right">出生日期：</div>
              <div class="am-u-md-3 am-u-end" style="padding-left: 0px;">
                <input type="date"  class="am-form-field am-input-sm input_width"  placeholder="日期"  id='birthday' name='birthday' required="">
              </div>
              <div class="am-u-md-2 am-text-right">职务：</div>
              <div class="am-u-md-3 am-u-end" style="padding-left: 0px;">
                 <input type="text"  class="am-input-xl input_width"  id='duty_name' name='duty_name' required="" maxlength="50" >
              </div>
              
            </div>
            <hr/>
            <div class="am-g am-margin-top am-form-group">
              <div class="am-u-md-2 am-text-right">单位名称：</div>
              <div class="am-u-md-3 am-u-end" style="padding-left: 0px;">
                <select  id='organize_name' name='organize_name' class="input_width" required=""  onchange="organize_change()">
                  <option value=0 name="organize_name_0" id="organize_name_0"  >请选择单位</option>
                  {% for i in gsalist %}

                  <option value={{ i.organize_id }} >{{ i.name }}</option>

                  {% endfor %}  
                </select>
                
              </div>
              <div class="am-u-md-2 am-text-right">电话：</div>
              <div class="am-u-md-3 am-u-end" style="padding-left: 0px;">
                <input type="text"  class="am-input-xl input_width"  onblur="if(/[^(1\d{10})]/g.test(value))AlertMSG('请输入11位电话号码！')" maxlength="50"  id='mobile' name='mobile' required="">
              </div>
              
            </div>
            <hr/>
            <div class="am-g am-margin-top am-form-group">
              <div class="am-u-md-2 am-text-right">部门名称：</div>
              <div class="am-u-md-3 am-u-end" style="padding-left: 0px;">
                <select  id='dept_name' name='dept_name' class="input_width" required="">
                  <option value=0 name="dept_name_0" id="dept_name_0"  >请选择部门</option>
                  {% for i in gsalist %}
                  {% for j in i.department %}
                  <option value={{ j.organize_id }} name="dept_name_{{ i.organize_id }}" style="display: none;" >{{ j.name }}</option>
                  {% endfor %}
                  {% endfor %}  
                </select>
              </div>
              
              <div class="am-u-md-2 am-text-right">邮箱：</div>
              <div class="am-u-md-3 am-u-end" style="padding-left: 0px;">
                <input type="text" class="am-input-xl input_width" id='email' maxlength="50"  onblur="if(/[^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]]/g.test(value))AlertMSG('请输入正确的邮箱格式！')" name='email' required="">
              </div>
            </div> 
            <hr/>   
            <div class="am-g am-margin-top am-form-group">
              <div class="am-u-md-2 am-text-right">备注：</div>
              <div class="am-u-md-3 am-u-end" style="padding-left: 0px;">
                <input type="text" class="am-input-xl input_width" id='description' maxlength="100"  style="width: 500px"  name='description' required="">
              </div>

            </div>       
            
          </div>
          
        </div>
        <div class="am-u-md-7">
          <div class="am-btn-toolbar">
            <div class="am-btn-group am-btn-group-xs">
            <div class="am-margin">
              <button type="button" class="am-btn am-btn-primary am-btn-xs" onclick="user_submit()">保存</button>
            </div>

            </div>
          </div>
        </div>

      </div>
    </div>

  </div>



<!--[if lt IE 9]>
<script src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script>
<script src="http://cdn.staticfile.org/modernizr/2.8.3/modernizr.js"></script>
<script src="assets/js/amazeui.ie8polyfill.min.js"></script>
<![endif]-->

<!--[if (gte IE 9)|!(IE)]><!-->
<script src="/static/assets/js/jquery.min.js"></script>
<!--<![endif]-->
<script src="/static/assets/js/amazeui.min.js"></script>
<script src="/static/assets/js/amazeui.tree.js"></script>
<script src="/static/assets/datatables/amazeui.datatables.min.js"></script>
<script src="/static/assets/dialog/amazeui.dialog.min.js"></script>
<link rel="stylesheet" type="text/css" href="/static/assets/css/amazeui.tree.css" />
<script src="/static/assets/js/app.js"></script>
<script type="text/javascript">
  $.ajaxSetup({
    data: {csrfmiddlewaretoken: '{{ csrf_token }}' },
  });


function organize_change(){
  var organize_id = $('#organize_name option:selected').val();
  $('#dept_name option').css("display","none")
  $('#dept_name option[name^=dept_name_'+organize_id+']').css("display","block")
  $('#dept_name option[name^=dept_name_0]').css("display","block")
  $('#dept_name')[0].selectedIndex = 0; 

  //console.log($('#dept_name_0').text())
  //$('#dept_name_0').attr("selected","selected");
}


function user_submit(){
  var login_name = document.getElementById("login_name").value;
  var role_id = $('#role option:selected').val();
  //var parent_name = $('#role option:selected').text();
  var real_name = document.getElementById("real_name").value;
  var sex = $('#sex option:selected').val();
  var birthday = document.getElementById("birthday").value;
  var organize_name = $('#organize_name option:selected').text();
  var organize_id = $('#organize_name option:selected').val();
  var dept_name = $('#dept_name option:selected').text();
  var dept_id = $('#dept_name option:selected').val();
  var duty_name = document.getElementById("duty_name").value;
  var mobile = document.getElementById("mobile").value;
  var email = document.getElementById("email").value;
  var description = document.getElementById("description").value;
 
  if(login_name==''){
    AlertMSG("请填写账号！")
  }else if (real_name==''){
    AlertMSG("请填写姓名！")
  }else if (birthday==''){
    AlertMSG("请填写出生日期！")
  }else if (organize_name=='请选择单位'){
    AlertMSG("请选择单位！")
  }else if (dept_name=='请选择部门'){
    AlertMSG("请选择部门！")
  }else if (duty_name==''){
    AlertMSG("请填写职务！")
  }else if (mobile==''){
    AlertMSG("请填写联系电话！")
  }else if (email==''){
    AlertMSG("请填写邮箱！")
  }else if (description==''){
    AlertMSG("请填写备注！")
  }else {
    //window.open("/XTGL_YHGL_5/?login_name="+login_name+"&role_id="+role_id+"&real_name="+real_name+"&sex="+sex+"&birthday="+birthday+"&organize_name="+organize_name+"&organize_id="+organize_id+"&dept_name="+dept_name+"&dept_id="+dept_id+"&duty_name="+duty_name+"&mobile="+mobile+"&email="+email+"")
    $.ajax({
      "url":"/XTGL_YHGL_5/",
      "data":{"login_name":login_name,"role_id":role_id,"real_name":real_name,"sex":sex,"birthday":birthday,"organize_name":organize_name,"organize_id":organize_id,"dept_name":dept_name,"dept_id":dept_id,"duty_name":duty_name,"mobile":mobile,"email":email,"description":description},
      "datatype":"json",
      "type":"post",
      "async":"false"
    }).success(function(data){
      if (data.status == 1) {
        var index = parent.layer.getFrameIndex(window.name);
        parent.location.reload();
        parent.layer.close(index);


      } else {
        AlertMSG(data.message)
      }
    }).error(function(data){
      AlertMSG("保存失败！")
    });
  }
}


var AlertMSG=function(msg){
    AMUI.dialog.alert({ title: '错误提示', content: msg, onConfirm: function() { console.log('close'); } });
}
</script>
</body>

</html>